 
  
package com.cmsz.paydemo.notify;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;

import com.cmsz.paydemo.util.FileUtil;
import com.cmsz.paydemo.util.SignUtil;

/**  
 *  
 * @TODO  ADD REASON 
 * @Date  2017年4月29日 下午11:08:45   
 * @author   Edison_lv  
 * @version            
 */
public class PayNotify {
	public static void main(String[] args) {
		try{
		//客户端
		//1、创建客户端Socket，指定服务器地址和端口
		Socket socket =new Socket("127.0.0.1",8080);
		//2、获取输出流，向服务器端发送信息
		OutputStream os = socket.getOutputStream();//字节输出流
		PrintWriter pw =new PrintWriter(os);//将输出流包装成打印流
		//获取报文
		String reqData = FileUtil.getData("payNotifyData.xml");
		//签名
		reqData = SignUtil.sign(reqData);
		 
		pw.write(reqData);
		pw.flush();
		socket.shutdownOutput();
		//3、获取输入流，并读取服务器端的响应信息
		InputStream is = socket.getInputStream();
		BufferedReader br = new BufferedReader(new InputStreamReader(is));
		String info = null;
		StringBuffer sb = new StringBuffer();
		while((info=br.readLine())!=null){
			sb.append(info);
		}
		String rspData = sb.toString();
		System.out.println("异步结果通知返回报文数据："+rspData);
		Boolean signFlag = SignUtil.checkSign(rspData);
		System.out.println("异步结果通知返回报文验签结果："+signFlag);
		  
		//4、关闭资源
		br.close();
		is.close();
		pw.close();
		os.close();
		socket.close();
		}catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}finally{
			
		}
	}
}
  
